package com.lgm.ht.common.result;

import com.lgm.ht.vo.BaseVO;
import lombok.Data;

@Data
public class Result {
    private Integer code;
    private BaseVO data;
    private String message;

    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public Result(ResultCode resultCode, BaseVO data) {
        this.code = resultCode.getCode();
        this.data = data;
    }

    public Result(ResultCode resultCode, String message) {
        this.code = resultCode.getCode();
        this.message = message;
    }

    public Result(ResultCode resultCode, BaseVO data, String message) {
        this.code = resultCode.getCode();
        this.data = data;
        this.message = message;
    }

    public static Result success() {
        return new Result(ResultCode.SUCCESS);
    }

    public static Result success(BaseVO data) {
        return new Result(ResultCode.SUCCESS, data);
    }

    public static Result success(String message) {
        return new Result(ResultCode.SUCCESS, message);
    }

    public static Result success(BaseVO data, String message) {
        return new Result(ResultCode.SUCCESS, data, message);
    }

    public static Result failed() {
        return new Result(ResultCode.FAILED);
    }

    public static Result failed(String message) {
        return new Result(ResultCode.FAILED, message);
    }

    public String getMessage() {
        if (this.message == null) {
            this.message = "";
        }
        return message;
    }
}
